package com.example.mymatch.controller;

import com.example.mymatch.model.Pm;
import com.example.mymatch.service.IPmService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "党员")
@RestController
public class PmController {
    @Autowired
    private IPmService pmService;//对某个业务服务的内容进行定义规范  编写者：谢楷诗
    @ApiOperation(value = "查询所有党员信息",notes = "获取党员信息返回json字符串")
    @RequestMapping("/getStr22")
    public String getPm(){return "My pm";}
    @CrossOrigin
    @ApiOperation(value = "对党员信息的添加方法")
    @GetMapping("/addPm")
    public int addPm(Pm pm){
        System.out.println("进入添加党员信息接口");
        return pmService.insertPm(pm);
    }

    @GetMapping("getAll22")
    @ApiOperation(value = "对党员信息查询方法")
    public List<Pm> getAllPm(Pm pm){
        System.out.println("进入查询方法");
        List<Pm> listPm=pmService.getAllPm(pm);
        return listPm;
    }
    @PutMapping("/editPm")
    @ApiOperation(value = "对党员信息的修改方法")
    public int EditPm(@RequestBody Pm pm){
        System.out.println("进入党员修改方法");
        return pmService.updatePm(pm);
    }
    @GetMapping("/delPm")
    @ApiOperation(value = "对党员信息的删除方法")
    public int Delete(String name){
        System.out.println("进入党员删除方法");
        int returnValue=0;
        if (name!= null){
            Pm pm=new Pm();
            pm.setPmName(name);
            returnValue= pmService.deletePm(pm);
        }
        return returnValue;
    }
    @GetMapping("/getOne22")
    @ApiOperation(value = "对单条党员信息的查询方法")
    public Pm getPm(String name){
        Pm pm=new Pm();
        System.out.println("进入单条查询方法");
        if (name!=null){
            Pm pm1=new Pm();
            pm1.setPmName(name);
            pm=pmService.getPm(pm1);
            System.out.println("返回的数据集合为："+pm.getPmName());
        }
        return pm;
    }
}
